
# coding:utf-8
import copy
import numpy as np
import os
import open3d as o3d
# print("->正在加载点云... ")
# pcd = o3d.io.read_point_cloud("plant.pcd")
# print(pcd)


def cal_aabb(pcd):
    print("->正在计算点云轴向最小包围盒...")
    aabb = pcd.get_axis_aligned_bounding_box()
    # print(aabb.get_min_bound())
    # print(aabb.get_max_bound())
    sasd=aabb.get_max_bound()-aabb.get_min_bound()
    print(np.array(aabb.get_box_points()))
    aabb.color = (1, 0, 0)
    print("->正在计算点云最小包围盒...")
    obb = pcd.get_oriented_bounding_box()
    print(np.array(obb.get_box_points()))


    obb.color = (0, 1, 0)
    # o3d.visualization.draw_geometries([pcd, aabb, obb], window_name="wechat 394467238")
    os.system("./py/area plant.pcd 0.001 ")

    return sasd
# for p in pcd.points:
#     print(p[0],p[1])
# cal_aabb(pcd)
# o3d.visualization.draw_geometries([pc3], window_name="wechat 394467238")

# pts=np.array(pcd.points)
# np.savetxt("a.txt",pts[:,:2])
# pts[:,2]=0
# pts2=np.array(pcd2.points)
# pts2[:,2]=0.10


# pcd2.points=o3d.utility.Vector3dVector(pts2)
# pcd.points=o3d.utility.Vector3dVector(pts)
# pc3=pcd+pcd2


# pcd.paint_uniform_color((1, 0, 0))

# pcd2.points=o3d.utility.Vector3dVector(pts2)

# hull, _ = pcd.compute_convex_hull()
# hull_ls = o3d.geometry.LineSet.create_from_triangle_mesh(hull)
# hull_ls.paint_uniform_color((1, 0, 0))
# o3d.visualization.draw_geometries([pcd, hull_ls])


# volume = pcd.get_volume()      # 计算体积
# # print("表面积为：", area)
# print("体积为：", volume)
